﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.Models.Year
{
    public class CompanyYearSum
    {
        public int Id { get; set; }

        public int Year { get; set; }

        /// <summary>
        /// 平仓盈亏
        /// </summary>
        public double Profit { get; set; }
        /// <summary>
        /// 手续费
        /// </summary>
        public double Free { get; set; }
        /// <summary>
        /// 净收益
        /// </summary>
        public double DayCount { get; set; }
        /// <summary>
        /// 交易笔数
        /// </summary>
        public double BillCount { get; set; }
        /// <summary>
        /// 总亏损
        /// </summary>
        public double SumLost { get; set; }
        /// <summary>
        /// 总盈利
        /// </summary>
        public double SumWin { get; set; }
        /// <summary>
        /// 保证金占用
        /// </summary>
        public double UsedMargin { get; set; }

        /// <summary>
        /// 资金利用率
        /// </summary>
        public double Utilization { get; set; }
        /// <summary>
        /// 胜率
        /// </summary>
        public double WinRate { get; set; }
        /// <summary>
        /// 涨幅
        /// </summary>
        public double RaiseRate { get; set; }

        /// <summary>
        /// 每笔盈利
        /// </summary>
        public double AvgBillBenefit { get; set; }

        /// <summary>
        /// 超过止损次数
        /// </summary>
        public double OverStopLoss { get; set; }

        /// <summary>
        /// 风险次数
        /// </summary>
        public int RiskCount { get; set; }

        /// <summary>
        /// 收益率
        /// </summary>
        public double Yield { get; set; }
        /// <summary>
        /// 最大回撤
        /// </summary>
        public double MaxReturn { get; set; }
        /// <summary>
        /// 平均持仓时间
        /// </summary>
        public double AvgPostionTime { get; set; }
        /// <summary>
        /// 平进平出单量
        /// </summary>
        public int PingJinPing { get; set; }
        /// <summary>
        /// 盈利次数
        /// </summary>
        public int WinCount { get; set; }
        /// <summary>
        /// 亏损次数
        /// </summary>
        public int LoseCount { get; set; }

        ///// <summary>
        ///// 保存月总值
        ///// </summary>
        ///// <param name="tradeHistoryId">插入时间编号</param>
        ///// <param name="pdate">插入时间</param>
        //public void InitCompanyYearSum(int year, DB.DBManager db)
        //{
        //    CompanyYearSum sum = new CompanyYearSum();
        //    var query = db.CompanyYearSum.Where(a => a.Year == year);
        //    var queryMonthList = db.CompanyMonthSum.Where(a => a.Year == year);
        //    if (query.Count() != 0)
        //    {
        //        sum = query.First();
        //    }
        //    sum.AvgBillBenefit = queryMonthList.Sum(a => a.AvgBillBenefit);
        //    sum.AvgPostionTime = queryMonthList.Sum(a => a.AvgPostionTime);
        //    sum.BillCount = queryMonthList.Sum(a => a.BillCount);
        //    sum.DayCount = queryMonthList.Sum(a => a.DayCount);
        //    sum.Free = queryMonthList.Sum(a => a.Free);
        //    sum.LoseCount = queryMonthList.Sum(a => a.LoseCount);
        //    sum.OverStopLoss = queryMonthList.Sum(a => a.OverStopLoss);
        //    sum.MaxReturn = queryMonthList.Sum(a => a.MaxReturn);
        //    sum.PingJinPing = queryMonthList.Sum(a => a.PingJinPing);
        //    sum.Profit = queryMonthList.Sum(a => a.Profit);
        //    sum.RaiseRate = queryMonthList.Sum(a => a.RaiseRate);
        //    sum.RiskCount = queryMonthList.Sum(a => a.RiskCount);
        //    sum.SumLost = queryMonthList.Sum(a => a.SumLost);
        //    sum.SumWin = queryMonthList.Sum(a => a.SumWin);
        //    sum.UsedMargin = queryMonthList.Sum(a => a.UsedMargin);
        //    sum.Utilization = queryMonthList.Sum(a => a.Utilization);
        //    sum.WinCount = queryMonthList.Sum(a => a.WinCount);
        //    sum.WinRate = queryMonthList.Sum(a => a.WinRate);
        //    sum.Yield = queryMonthList.Sum(a => a.Yield);
        //    sum.Year = year;
        //    if (query.Count() == 0)
        //    {
        //        db.CompanyYearSum.Add(sum);
        //    }

        //    db.SaveChanges();
        //}



        ///// <summary>
        ///// 获取公司日总值
        ///// </summary>
        ///// <param name="accountid"></param>
        ///// <param name="tradeHistoryId"></param>
        ///// <returns></returns>
        //public CompanyYearSum GetCompanyYearSum(int year, DB.DBManager db)
        //{
        //    CompanyYearSum count = new CompanyYearSum();
        //    var query = db.CompanyYearSum.Where(a => a.Year == year);
        //    if (query.Count() > 0)
        //    {
        //        count = query.First();
        //    }
        //    return count;
        //}

        //public void Delete(int year, DB.DBManager db)
        //{
        //    var query = db.CompanyYearSum.Where(a => a.Year == year);
        //    if (query.Count() > 0)
        //    {
        //        db.CompanyYearSum.Remove(query.First());
        //        db.SaveChanges();
        //    }
        //}
    }
}
